if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=ucs-bom,utf-8,latin1
endif

set nocompatible	" Use Vim defaults (much better!)
set bs=indent,eol,start		" allow backspacing over everything in insert mode
"set ai			" always set autoindenting on
"set backup		" keep a backup file
set viminfo='20,\"50	" read/write a .viminfo file, don't store more
			" than 50 lines of registers

" Only do this part when compiled with support for autocommands
if has("autocmd")
  augroup redhat
  autocmd!
  " In text files, always limit the width of text to 78 characters
  " autocmd BufRead *.txt set tw=78
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
  " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
  autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
  " start with spec file template
  autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
  augroup END
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add $PWD/cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != ""
      cs add $CSCOPE_DB
   endif
   set csverb
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

filetype plugin on

if &term=="xterm"
     set t_Co=8
     set t_Sb=[4%dm
     set t_Sf=[3%dm
endif

" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"

" 语法高亮与检查
syntax enable
syntax on

" molokai主题配置文件
set t_Co=256
set background=dark
let g:solarized_termcolors=256
colorscheme molokai

" 总是显示状态栏
set laststatus=2      
highlight StatusLine cterm=bold ctermfg=yellow ctermbg=blue

" 获取当前路径，将$HOME转化为~
function! CurDir()
        let curdir = substitute(getcwd(), $HOME, "~", "g")
        return curdir
endfunction

set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurDir()}\ \ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\ \".&fenc)}\ \|\ %{$USER}\ @\ %{hostname()}\
" 显示文件名：总行数，总的字符
set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%] 
" 在编辑过程中，在右下角显示光标位置的状态行
set ruler 

" 与识别文件和自动加载高亮有关
filetype on
filetype indent on 
filetype plugin on
filetype plugin indent on

" vim 自动保存
" 切换tag自动保存
set autowriteall
" 自动保存
let g:auto_save = 1
let g:auto_save_events = ["InsertLeave", "TextChanged", "TextChangedI", "CursorHoldI", "CompleteDone"]

" 启动时显示行号
set nu

" 显示行列效果
set cursorline 
set cursorcolumn


" 在底部显示、当前处于什么模式
set showmode

" 命令行模式下，在底部显示，当前键入的指令，比如2y3d
set showcmd

" 使用utf8
set encoding=utf-8  

" 按下回车键后，下一行的缩进会自动跟上一行的缩进保持一致
set autoindent

" 按下 Tab 键时，Vim 显示的空格数
set tabstop=4

" 在文本上按下>>（增加一级缩进）、<<（取消一级缩进）或者==（取消全部缩进）时，每一级的字符数
set shiftwidth=4

" 光标遇到圆括号、方括号、大括号时，自动高亮对应的另一个圆括号、方括号和大括号
set showmatch

" 搜索时，高亮显示匹配结果
set hlsearch

" 输入搜索模式时，每输入一个字符，就自动跳到第一个匹配的结果
set incsearch


" 不创建交换文件
set noswapfile

" 不创建备份文件
set nobackup

" 保留撤销历史
" set undofile

" Vim 需要记住多少次历史操作。
set history=1000

" 出错时，发出视觉提示，通常是屏幕闪烁
set visualbell

" 打开文件监视。如果在编辑过程中文件发生外部改变（比如被别的编辑器编辑了），就会发出提示
set autoread

" 命令模式下，底部操作指令按下 Tab 键自动补全。第一次按下 Tab，会显示所有匹配的操作指令的清单；第二次按下 Tab，会依次选择各个指令
set wildmenu
set wildmode=longest:list,full

" pathogen config
execute pathogen#infect()
filetype plugin indent on

" nedtred
" 设置快捷键
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>

" 修改树的显示图标
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'

" 窗口位置
let g:NERDTreeWinPos='left'

" 窗口代销
let g:NERDTreeSize=30

"窗口是否显示行号
let g:NERDTreeShowLineNumbers=0

" 不显示隐藏文件
let g:NERDTreeHidden=0

" 打开vim时如果没有文件自动打开NERDTree
autocmd vimenter * if !argc()|NERDTree|
